package com.jdd.modules.sdk.utils;

import com.sun.jna.Library;
import com.sun.jna.Pointer;
import com.sun.jna.Structure;
import com.sun.jna.win32.StdCall;

import java.util.Arrays;
import java.util.List;

/**
 * author:lcy
 * since 2021/6/29 18:18
 */
public interface QIANYISDK extends Library, StdCall{


    int Net_QueryConnState(int var1);

    int Net_GateSetup(int var1, QIANYISDK.T_ControlGate.ByReference var2);

    int Net_Init();

    int Net_QueryNETSetup(int var1, QIANYISDK.T_NetSetup.ByReference var2);

    int Net_SaveImageToJpeg(int var1, String var2);

    int Net_AddCamera(String var1);

    int Net_ConnCamera(int var1, short var2, short var3);

    int Net_RegImageRecvEx(int var1, Callback_FGetImageCBEx.FGetImageCBEx var2, Pointer var3);

    int Net_SendRS485Data(int var1, QIANYISDK.T_RS485Data.ByReference var2);

    /**
     * 软触发
     *
     * @param var1
     * @param var2
     * @return
     */
    int Net_ImageSnap(int var1, QIANYISDK.T_RS485Data.ByReference var2);

    public static class T_RS485Data extends Structure {
        public byte rs485Id;
        public byte ucReserved;
        public short dataLen;
        public byte[] data = new byte[1024];

        public T_RS485Data() {
        }

        @Override
        protected List getFieldOrder() {
            return Arrays.asList("rs485Id", "ucReserved", "dataLen", "data");
        }

        public static class ByReference extends QIANYISDK.T_RS485Data implements Structure.ByReference {
            public ByReference() {
            }
        }

        public static class ByValue extends QIANYISDK.T_RS485Data implements Structure.ByValue {
            public ByValue() {
            }
        }
    }

    public static class T_ControlGate extends Structure {
        public byte ucState;
        public byte[] ucReserved = new byte[3];

        public T_ControlGate() {
        }

        @Override
        protected List getFieldOrder() {
            return Arrays.asList("ucState", "ucReserved");
        }

        public static class ByReference extends QIANYISDK.T_ControlGate implements Structure.ByReference {
            public ByReference() {
            }
        }

        public static class ByValue extends QIANYISDK.T_ControlGate implements Structure.ByValue {
            public ByValue() {
            }
        }
    }
    public static class T_NetSetup extends Structure {
        public byte ucEth;
        public byte[] aucReserved = new byte[3];
        public int uiIPAddress;
        public int uiMaskAddress;
        public int uiGatewayAddress;
        public int uiDNS1;
        public int uiDNS2;
        public byte[] szHostName = new byte[16];

        public T_NetSetup() {
        }

        @Override
        protected List getFieldOrder() {
            return Arrays.asList("ucEth", "aucReserved", "uiIPAddress", "uiMaskAddress", "uiGatewayAddress", "uiDNS1", "uiDNS2", "szHostName");
        }

        public static class ByReference extends QIANYISDK.T_NetSetup implements Structure.ByReference {
            public ByReference() {
            }
        }

        public static class ByValue extends QIANYISDK.T_NetSetup implements Structure.ByValue {
            public ByValue() {
            }
        }
    }
    public static class T_ImageUserInfo extends Structure {
        public short usWidth;
        public short usHeight;
        public byte ucVehicleColor;
        public byte ucVehicleBrand;
        public byte ucVehicleSize;
        public byte ucPlateColor;
        public byte[] szLprResult = new byte[16];
        public short[] usLpBox = new short[4];
        public byte ucLprType;
        public short usSpeed;
        public byte ucSnapType;
        public byte ucReserved;
        public byte[] acSnapTime = new byte[18];
        public byte ucViolateCode;
        public byte ucLaneNo;
        public int uiVehicleId;
        public byte ucScore;
        public byte ucDirection;
        public byte ucTotalNum;
        public byte ucSnapshotIndex;

        public T_ImageUserInfo() {
        }

        @Override
        protected List getFieldOrder() {
            return Arrays.asList("usWidth", "usHeight", "ucVehicleColor", "ucVehicleBrand", "ucVehicleSize", "ucPlateColor", "szLprResult", "usLpBox", "ucLprType", "usSpeed", "ucSnapType", "ucReserved", "acSnapTime", "ucViolateCode", "ucLaneNo", "uiVehicleId", "ucScore", "ucDirection", "ucTotalNum", "ucSnapshotIndex");
        }

        public static class ByReference extends QIANYISDK.T_ImageUserInfo implements Structure.ByReference {
            public ByReference() {
            }
        }

        public static class ByValue extends QIANYISDK.T_ImageUserInfo implements Structure.ByValue {
            public ByValue() {
            }
        }
    }
    public static class T_PicInfo extends Structure {
        public int uiPanoramaPicLen;
        public int uiVehiclePicLen;
        public Pointer ptPanoramaPicBuff;
        public Pointer ptVehiclePicBuff;

        public T_PicInfo() {
        }

        @Override
        protected List getFieldOrder() {
            return Arrays.asList("uiPanoramaPicLen", "uiVehiclePicLen", "ptPanoramaPicBuff", "ptVehiclePicBuff");
        }

        public static class ByReference extends QIANYISDK.T_PicInfo implements Structure.ByReference {
            public ByReference() {
            }
        }

        public static class ByValue extends QIANYISDK.T_PicInfo implements Structure.ByValue {
            public ByValue() {
            }
        }
    }
    public static enum E_ReturnCode {
        DC_UNDEFINED_ERROR(-1),
        DC_NO_ERROR(0),
        DC_HANDLE_INVALID(1),
        DC_CONN_FAIL(2),
        DC_OBJ_BUSY(3),
        DC_OBJ_UNEXIST(4),
        DC_CMD_INVALID(5),
        DC_PARA_INVALID(6),
        DC_REQ_TIMEOUT(7),
        DC_MEMORY_LACK(8),
        DC_SEND_FAIL(9),
        DC_RECV_FAIL(10),
        DC_OPT_FAIL(11),
        DC_NOT_CONN(12),
        DC_BEYOND_MAX_CLIENT(13),
        DC_CONNECT_AUTH(18),
        DC_USER_NOT_EXIST(19),
        DC_PASSWD_ERROR(20);

        private int tmp = 0;

        private E_ReturnCode(int temp) {
            this.tmp = temp;
        }

        public int getValue() {
            return this.tmp;
        }
    }

}

